package com.shujia.tour.web.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;

import java.util.HashMap;

/**
 * 游客数据查询接口
 */
@RestController
public class TourDataQueryInterface {


    @RequestMapping("/query")
    public HashMap<String, Long> query(String pid, String dayId, String cname) {

        String key = pid + "_" + dayId;

        //创建redis连接
        Jedis jedis = new Jedis("node2", 6379);
        jedis.select(10);
        String hget = jedis.hget(key, cname);

        String[] split = hget.split("\\|");

        HashMap<String, Long> map = new HashMap<>();

        if (split.length == 1) {
            map.put("flow", Long.parseLong(hget));
            return map;
        }
        for (String s : split) {
            String[] split1 = s.split(":");
            String c = split1[0];
            String flow = split1[1];
            map.put(c, Long.parseLong(flow));
        }

        return map;
    }


}
